package acm.pta11;

import java.util.BitSet;
import java.util.Scanner;

public class 刮刮彩票 {

    static final int[] bonus = {
            0, 0, 0, 0, 0, 0,
            10000, 36, 720,
            360, 80, 252,
            108, 72, 54,
            180, 72, 180,
            119, 39, 306,
            1080, 144, 1800,
            3600,
    };

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] arr = new int[3][3];
        BitSet bitSet = new BitSet(10);
        int row = 0, clo = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                arr[i][j] = sc.nextInt();
                if (arr[i][j] == 0) {
                    row = i;
                    clo = j;
                } else {
                    bitSet.set(arr[i][j]);
                }
            }
        }
        bitSet.flip(1, 10);
        arr[row][clo] = bitSet.stream().iterator().next();

        System.out.println(arr[sc.nextInt() - 1][sc.nextInt() - 1]);
        System.out.println(arr[sc.nextInt() - 1][sc.nextInt() - 1]);
        System.out.println(arr[sc.nextInt() - 1][sc.nextInt() - 1]);

        int d = sc.nextInt();
        switch (d){
            case 1:
                System.out.println(bonus[arr[0][0]+arr[0][1]+arr[0][2]]);
                return;
            case 2:
                System.out.println(bonus[arr[1][0]+arr[1][1]+arr[1][2]]);
                return;
            case 3:
                System.out.println(bonus[arr[2][0]+arr[2][1]+arr[2][2]]);
                return;
            case 4:
                System.out.println(bonus[arr[0][0]+arr[1][0]+arr[2][0]]);
                return;
            case 5:
                System.out.println(bonus[arr[0][1]+arr[1][1]+arr[2][1]]);
                return;
            case 6:
                System.out.println(bonus[arr[0][2]+arr[1][2]+arr[2][2]]);
                return;
            case 7:
                System.out.println(bonus[arr[0][0]+arr[1][1]+arr[2][2]]);
                return;
            case 8:
                System.out.println(bonus[arr[0][2]+arr[1][1]+arr[2][0]]);
        }
    }
}
